import 'package:flutter/material.dart';
import 'package:flutter_bilibili/core/extension/int_extension.dart';
import 'package:flutter_bilibili/core/model/live_room_model.dart';
import 'package:flutter_bilibili/ui/pages/live/live_room_play.dart';
import 'package:flutter_bilibili/ui/shared/image_assets.dart';

import '../../../core/model/live_rooms_model.dart';
import '../../shared/app_theme.dart';

class HYLiveRoomItem extends StatefulWidget {
  LiveRoomModel liveRoom;

  HYLiveRoomItem(this.liveRoom);

  @override
  State<HYLiveRoomItem> createState() => _HYLiveRoomItemState();
}

class _HYLiveRoomItemState extends State<HYLiveRoomItem> {
  final _radius = 6.px;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.of(context).pushNamed(HYLiveRoomPlayScreen.routeName,
            arguments: widget.liveRoom);
      },
      child: Card(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(_radius),
            topRight: Radius.circular(_radius),
          ),
        ),
        child: Column(
          children: [
            Stack(
              children: [
                buildHomeVideoItemCover(widget.liveRoom),
                Positioned(
                  left: 5.px,
                  bottom: 5.px,
                  child: Text(
                    widget.liveRoom.uName,
                    style: TextStyle(
                        color: Color.fromRGBO(255, 255, 255, 1),
                        fontSize: HYAppTheme.xxxSmallFontSize),
                  ),
                ),
                Positioned(
                  right: 5.px,
                  bottom: 5.px,
                  child: Text.rich(
                    TextSpan(
                      children: [
                        WidgetSpan(
                            alignment: PlaceholderAlignment.middle,
                            child: Image.asset(
                              ImageAssets.seenPNG,
                              width: 12.px,
                              height: 12.px,
                            )),
                        TextSpan(
                          text: "  " + widget.liveRoom.watchedShowTextLarge,
                          style: TextStyle(
                              color: Color.fromRGBO(255, 255, 255, 1),
                              fontSize: HYAppTheme.xxSmallFontSize),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
            Container(
              alignment: Alignment.topLeft,
              padding: EdgeInsets.only(
                  top: 8.px, left: 8.px, right: 8.px, bottom: 8.px),
              child: Text(
                widget.liveRoom.title,
                style: TextStyle(
                    fontSize: HYAppTheme.xSmallFontSize, color: Colors.black),
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            Container(
              alignment: Alignment.topLeft,
              padding: EdgeInsets.only(
                bottom: 3.px,
                left: 8.px,
                right: 8.px,
              ),
              child: Text(
                widget.liveRoom.areaV2Name,
                style: TextStyle(
                    fontSize: HYAppTheme.xxSmallFontSize,
                    color: Color.fromRGBO(156, 156, 158, 1)),
              ),
            )
          ],
        ),
      ),
    );
  }

  //视频封面
  Widget buildHomeVideoItemCover(LiveRoomModel liveRoom) {
    return ClipRRect(
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(_radius),
        topRight: Radius.circular(_radius),
      ),
      child: Image.network(
        liveRoom.cover,
        width: double.infinity,
        height: 110.px,
        fit: BoxFit.fill,
      ),
    );
  }
}
